View Javadoc
1 /*** 2 3 * TreeReport 4 5 * 6 7 * This basically provides a textual 8 9 * tree showing what was covered, and 10 11 * what wasn't. 12 13 */ 14 15 16 17 package junit.quilt.reports; 18 19 20 21 import javax.swing.tree.*; 22 23 24 25 import java.io.OutputStream; 26 27 import java.io.OutputStreamWriter; 28 29 import java.io.PrintWriter; 30 31 import java.io.IOException; 32 33 34 35 import java.util.Enumeration; 36 37 import java.util.Iterator; 38 39 import java.util.Map; 40 41 42 43 import junit.quilt.framework.*; 44 45 46 47 public class TreeReport 48 49 extends Object 50 51 implements Report 52 53 { 54 55 private static final String PREFIX="+--"; 56 private static final String INDENT = " "; 57 58 public TreeReport() { } 59 60 61 62 public void writeNode( PrintWriter out, 63 64 QuiltRegistry registry, 65 66 int level, 67 68 String levels[], 69 70 TreeNode nodes[]) { 71 72 73 74 out.print(indent( level + 1)); // 2 space indentation per level. 75 76 out.println(PREFIX + nodes[level].toString() ); 77 78 79 80 if (level == levels.length - 1) { 81 82 TreePath tp = new TreePath( nodes ); 83 84 QuiltCollector collect = registry.getCollector( tp ); 85 86 if (collect != null) { 87 88 Map summary = collect.getSummary(); 89 90 Iterator i = summary.keySet().iterator(); 91 92 93 94 while (i.hasNext()) { 95 96 out.print(indent( level + INDENT.length() )); 97 98 String metric = (String) i.next(); 99 100 float percent = ((Float) summary.get(metric)).floatValue(); 101 102 out.println(PREFIX + metric + " (" + 103 104 percent * 100.0 + "%)"); 105 106 } 107 108 } 109 110 } else { 111 112 Enumeration children = nodes[level].children(); 113 114 while (children.hasMoreElements()) { 115 116 TreeNode next = (TreeNode) children.nextElement(); 117 118 nodes[level + 1] = next; 119 120 writeNode( out, registry, level + 1, levels, nodes ); 121 122 } 123 124 } 125 126 } 127 128 129 130 private String indent( int level ) { 131 132 StringBuffer RC = new StringBuffer(level*INDENT.length()); 133 134 for (int j = 0; j < level; j++) { 135 136 RC.append(INDENT); 137 138 } 139 140 return RC.toString(); 141 142 } 143 144 145 146 public void writeReport( OutputStream out, 147 148 QuiltRegistry registry ) 149 150 throws IOException 151 152 { 153 154 String levels[] = registry.getLevels(); 155 156 157 158 PrintWriter pw = new PrintWriter( new OutputStreamWriter( out )); 159 160 TreeNode nodes[] = new TreeNode[levels.length]; 161 162 163 164 nodes[0] = registry.getContents(); 165 166 writeNode( pw, registry, 0, levels, nodes ); 167 168 169 170 pw.flush(); 171 172 } 173 174 } 175

This page was automatically generated by Maven